/*******************************************************************************
 * File:      polygon.h                                                        *
 * Function:  implementation of polygon operation                              *
 * Author:    kvmaker                                                          *
 * Email:     kvmaker@gmail.com                                                *
 * Data:      24/Feb/2012                                                      *
 *                                                                             *
 * Copyright: kvmaker                                                          *
 *                                                                             *
 * Licensed under the Apache License, Version 2.0 (the "License");             *
 * you may not use this file except in compliance with the License.            *
 * You may obtain a copy of the License at                                     *
 *                                                                             *
 *    http://www.apache.org/licenses/LICENSE-2.0                               *
 *                                                                             *
 * Unless required by applicable law or agreed to in writing, software         *
 * distributed under the License is distributed on an "AS IS" BASIS,           *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    *
 * See the License for the specific language governing permissions and         *
 * limitations under the License.                                              *
 ******************************************************************************/
#ifndef __POLYGON__
#define __POLYGON__

/*******************************************************************************
 *                               INCLUDE                                       *
 ******************************************************************************/
#include "comdef.h"
#include "list.h"

/*******************************************************************************
 *                               DEFINE                                        *
 ******************************************************************************/
#define POLYGON_MAX_SIZE   2048

/*******************************************************************************
 *                               TYPEDEF                                       *
 ******************************************************************************/
typedef struct
{
    LIST_HEAD node;
    UINT32    size;     /* the maxium point this polygon can hold        */
    UINT32    num;      /* the actural number of point in this polygon   */
    POINT     *point;   /* the array of point*/
} POLYGON;

typedef struct 
{
    UINT32    num;      /* the actrual number of polygon in this set     */
    LIST_HEAD head;     /* the list head of all polygon                  */
} POLYGON_SET;

/*******************************************************************************
 *                               FUNCTION                                      *
 ******************************************************************************/
UINT32 polygon_create(UINT32 size, POLYGON **poly);
UINT32 polygon_destroy(POLYGON *poly);
UINT32 polygon_add_point(double x, double y, POLYGON *poly);

UINT32 polygon_set_create(UINT32 size, POLYGON_SET **poly_set);
UINT32 polygon_set_destroy(POLYGON_SET *poly_set);
UINT32 polygon_set_add_poly(POLYGON *poly, POLYGON_SET *poly_set);

UINT32 polygon_set_diff(POLYGON_SET *subject, POLYGON_SET *clip, 
                        POLYGON_SET **res);
UINT32 polygon_point_in(POINT *a, POLYGON *poly);

#endif /*__POLYGON__*/

